package logic

import (
	"context"
	"house_srv/house"
	"house_srv/internal/svc"
	"house_srv/mysql"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserListLogic {
	return &UserListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserListLogic) UserList(in *house.UserListRequest) (*house.UserListResponse, error) {
	// todo: add your logic here and delete this line
	var user mysql.User
	lists, err := user.UserList(in.Status, in.Page, in.PageSize)
	if err != nil {
		logx.Info("用户列表信息失败", err)
		return nil, err
	}
	var userList []*house.UserList
	for _, v := range lists {
		list := house.UserList{
			UserId: int64(v.ID),
			Mobile: v.Mobile,
			Avatar: v.Avatar,
			Status: v.Status,
		}
		userList = append(userList, &list)
	}
	return &house.UserListResponse{
		List: userList,
	}, nil
}
